package com.xbongbong.paas.help;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.TaskTypeEnum;
import com.xbongbong.paas.log.MongoLogHelp;
import com.xbongbong.paas.log.constant.LogMemoConstant;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.saas.enums.OperateModuleTypeEnum;
import com.xbongbong.saas.enums.OperateTypeEnum;
import javax.annotation.Resource;

/**
 * @version v1.0
 * @auther: youli.chen
 * @date: 审批日志
 * @since v1.0
 */
public class ProcessLogHelp {

    @Resource
    private MongoLogHelp mongoLogHelp;

    /**
     * 封装审批操作日志方法
     * @param corpid  公司id
     * @param creatId  审批人ID
     * @param creatName  审批人名称
     * @param taskType  操作，例如：1.同意，3.暂存，4.转交，5.回退，7.拒绝；可以参考com.xbongbong.paas.enums.TaskTypeEnum
     * @param userName  提交人名称
     * @param appName  表单名称
     * @param titleName  提交的名称，例如：合同名称(合同流水号)
     */
    public void processOperateLog(String corpid, String creatId, String creatName, Integer taskType, String userName, String appName, String titleName) throws XbbException {
        TaskTypeEnum taskTypeEnum = TaskTypeEnum.getTaskTypeEnum(taskType);
        OperateTypeEnum operateTypeEnum;
        switch (taskTypeEnum) {
            case COMMIT:
                operateTypeEnum = OperateTypeEnum.AGREE;
                break;
            case STORAGE:
                operateTypeEnum = OperateTypeEnum.STORAGE;
                break;
            case TRANSFER:
                operateTypeEnum = OperateTypeEnum.TRANSFER;
                break;
            case BACK:
                operateTypeEnum = OperateTypeEnum.BACK;
                break;
            case END:
                operateTypeEnum = OperateTypeEnum.REFUSE;
                break;
            default:
                operateTypeEnum = OperateTypeEnum.UNKNOWN;
        }
        String operaName = operateTypeEnum.getName();
        String memo = String.format(I18nMessageUtil.getMessage(LogMemoConstant.LOG_MEMO_USER_PROCESS_WORK), creatName, operaName, userName, appName, titleName);
        mongoLogHelp.buildLog(corpid, creatId, creatName, OperateModuleTypeEnum.APPROVAL, operateTypeEnum,
                "", titleName, memo, "");
    }
}
